using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SiteManager;
using System.Data.SqlClient;
public partial class SearchControl : System.Web.UI.UserControl
{
    // creating an instance of manager class
    Manager mgr = new Manager(true,"ConnectionString");

    protected void Page_Load(object sender, EventArgs e)
    {
        lblMesg.Text = "";
        if (!Page.IsPostBack)
        {

            // Used to store the doctrs id found based on the search

            FillCombos();
        }
       
        btnSearch.Attributes.Add("onclick", "return checkError();");
        
        txtCity.Attributes.Add("onfocus", "BlankSearchFields('" + txtCity.ClientID + "', 'City :');");
        txtZipCode.Attributes.Add("onfocus", "BlankSearchFields('" + txtZipCode.ClientID + "', 'Zipcode:');");
        txtLName.Attributes.Add("onfocus", "BlankSearchFields('" + txtLName.ClientID + "', 'Last Name:');");

        txtCity.Attributes.Add("onblur", "FillSearchFields('" + txtCity.ClientID + "', 'City :');");
        txtZipCode.Attributes.Add("onblur", "FillSearchFields('" + txtZipCode.ClientID + "', 'Zipcode:');");
        txtLName.Attributes.Add("onblur", "FillSearchFields('" + txtLName.ClientID + "', 'Last Name:');");
    }

    /// <summary>
    /// Fill all the combos on the page with default values from database.
    /// </summary>
    private void FillCombos()
    {
        //filling the dropdown list boxes        
        mgr.BindList("select id,name from tbl_speciality order by name", "Name", "Id", ddlSpeciality, "Specialty :");
        //mgr.BindList("select stateid,name from tbl_states order by name", "Name", "StateId", ddlState, "State :");
        mgr.BindList("select [countryname],countrycode from tbl_country where(countrycode='US')OR (countrycode='CA') order by [countryname]", "countryname", "countrycode", ddlCountry, "Country");
        ddlState.Items.Insert(0, new ListItem("State/Province", "0"));
        /////////////// changes (06/26/2007) PrimarySpeciality & Secondary Sepciality merged to find distinct specialities
        //mgr.BindList("select id,name from tbl_primaryspeciality order by name", "Name", "Id", ddlSubSpeciality, "select");
        mgr.BindList("select id, name from tbl_primaryspeciality union select id, name from tbl_Secondaryspeciality order  by name", "Name", "id", ddlSubSpeciality, "Sub-Specialty : ");
        /////////////// End Changes

        //Dentist DropDown
        mgr.BindList("select id as c, specialty from tbl_DentistSpecialty order by specialty", "specialty", "c", ddlDentistSpeciality, "Specialty");
        mgr.BindList("select id,specialty from tbl_DentistSubSpecialty order by specialty", "specialty", "Id", ddlDentistSubSpeciality, "Sub-Specialty :");
       // ddlSpeciality.Items.Insert(0, new ListItem("Select", "0"));
        //ddlState.Items.Insert(0, new ListItem("Minimum Rating:", "0"));

        //Filling the Ratings Combos
        string strText = "";
        for (int i = 101; i >= 69; i--)
        {
            if (i == 101)
            {
                ddlRating.Items.Add(new ListItem("All Ratings", "0"));
            }
            else
            {
                strText = i.ToString();
                if (i < 100)
                    strText = i.ToString(); // +" & Above";
                if (i == 69)
                {
                    strText = " All ";
                    //ddlRating.Items.Add(new ListItem(strText, "0"));
                }
                else
                    ddlRating.Items.Add(new ListItem(strText, i.ToString()));
            }
        }

    }
    private void DentisDDL()
    {
        mgr.BindList("select id as c, specialty from tbl_DentistSpecialty order by specialty", "specialty", "c", ddlDentistSpeciality, "Specialty");
        mgr.BindList("select id,specialty from tbl_DentistSubSpecialty order by specialty", "specialty", "Id", ddlDentistSubSpeciality, "Sub-Specialty :");
        // ddlSpeciality.Items.Insert(0, new ListItem("Select", "0"));
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        if (ddlDind.SelectedValue == "Doctor")
        {
            #region "Doctor Search"
            Session["Speciality"] = "";
            string qstring = "";

            if (ddlSpeciality.Items.Count > 1)
            {
                if (ddlSpeciality.SelectedIndex > 0)
                {
                    Session["Speciality"] = ddlSpeciality.SelectedItem.Text.Trim().Replace(" ", "_");        
                    qstring = Session["Speciality"].ToString();
                }
            }

            if (ddlState.Items.Count > 1)
            {
                if (ddlState.SelectedIndex > 0)
                {
                  
                    if (qstring == "")
                        qstring = ddlState.SelectedItem.Text.Trim().Replace(" ", "_");
                    else
                        qstring = qstring + "/" + ddlState.SelectedItem.Text.Trim().Replace(" ", "_");
                }
            }

            if (txtCity.Text.Trim().Equals("City :") || txtCity.Text.Trim() == "")
                txtCity.Text = "";
            else if (qstring == "")
            {
               qstring = txtCity.Text.Trim().Replace(" ", "_");
            
            }
            else
            {
                qstring = qstring + "/" + txtCity.Text.Trim().Replace(" ", "_");
               
            }

            if (txtZipCode.Text.Trim().Equals("Zipcode:") || txtZipCode.Text.Trim() == "")
                txtZipCode.Text = "";
            else if (qstring == "")
            {
              qstring = txtZipCode.Text.Trim().Replace(" ", "_");
             }
            else
            {
               qstring = qstring + "/" + txtZipCode.Text.Trim().Replace(" ", "_");
              
            }

            if (txtLName.Text.Trim().Equals("Last Name:"))
                txtLName.Text = "";
            Session["sDoctorsId"] = "";
            Session["PreDoctorsId"] = "";
            Session["EnFeaDoctorsId"] = "";
            Session["StdFeaDoctorsId"] = "";
            Session["Top3"] = "";
            Session["ZipCode"] = "";
            Session["City"] = "";
            Session["Travel_Dis"] = "";
            Session["State"] = "";

            #region calling stored procedure
            // get the search results
            try
            {
                SqlParameter[] sqlParam = new SqlParameter[9];
                sqlParam[0] = new SqlParameter("@state", SqlDbType.VarChar, 2);
                sqlParam[1] = new SqlParameter("@city", SqlDbType.VarChar, 50);
                sqlParam[2] = new SqlParameter("@zip", SqlDbType.VarChar, 10);
                sqlParam[3] = new SqlParameter("@SpecialtyID", SqlDbType.Int);
                sqlParam[4] = new SqlParameter("@Rate", SqlDbType.Int);
                sqlParam[5] = new SqlParameter("@FirstName", SqlDbType.VarChar, 200);
                sqlParam[6] = new SqlParameter("@LastName", SqlDbType.VarChar, 200);
                sqlParam[7] = new SqlParameter("@SubSpecialtyID", SqlDbType.VarChar, 100);
                sqlParam[8] = new SqlParameter("@TravelDistance", SqlDbType.Float);

                sqlParam[0].Value = ddlState.SelectedItem.Value.Equals("0") ? "" : ddlState.SelectedItem.Value;
                sqlParam[1].Value = txtCity.Text.Trim();
                sqlParam[2].Value = txtZipCode.Text.Trim();
                sqlParam[3].Value = ddlSpeciality.SelectedItem.Value;
                sqlParam[4].Value = ddlRating.SelectedItem.Value;
                sqlParam[5].Value = "";
                sqlParam[6].Value = txtLName.Text.Trim();
                sqlParam[7].Value = ddlSubSpeciality.SelectedItem.Value;
                sqlParam[8].Value = ddlDistance.SelectedItem.Value;
                Session["PreviousSpeciality"] = "";
                Session["PreviousSubSpeciality"] = "";
                 if (ddlSpeciality.SelectedIndex > 0)
                    Session["PreviousSpeciality"] = ddlSpeciality.SelectedItem.Text;
                if (ddlSubSpeciality.SelectedIndex > 0)
                    Session["PreviousSubSpeciality"] = ddlSubSpeciality.SelectedItem.Text;
               //DataSet ds_result = mgr.ExecuteQuery("DoctorSearch_HomePage", sqlParam, "tbl_srch");
                DataSet ds_result = mgr.ExecuteQuery("HomepageDocSearch", sqlParam, "tbl_srch");
                string DoctorsNonFeaIds = GetDoctorsId(ds_result);
                string PremiumDoctorsFeaturedIds = GetPremiumDoctorsIdFeat(ds_result, 1);
                string EnhancedDoctorsFeaturedIds = GetEnhancedDoctorsIdFeat(ds_result, 1);
                string StandardDoctorsFeaturedIds = GetStandardDoctorsIdFeat(ds_result, 1);
                // get top 3
                string Top3DrFeaturedIds = GetPremiumDoctorsIdFeat(ds_result, 2);

                if ((DoctorsNonFeaIds.Trim().Length > 0) || (PremiumDoctorsFeaturedIds.Trim().Length > 0) || (Top3DrFeaturedIds.Trim().Length > 0) || (EnhancedDoctorsFeaturedIds.Trim().Length > 0) || (StandardDoctorsFeaturedIds.Trim().Length > 0))
                {
                    Session["sDoctorsId"] = DoctorsNonFeaIds;
                    Session["PreDoctorsId"] = PremiumDoctorsFeaturedIds;
                    Session["EnFeaDoctorsId"] = EnhancedDoctorsFeaturedIds;
                    Session["StdFeaDoctorsId"] = StandardDoctorsFeaturedIds;
                    Session["Top3"] = Top3DrFeaturedIds;
                    Session["pageFromOrAction"] = "home";
                    if (ddlDistance.SelectedItem.Value.Trim() != "0") // to implement Distance Search Functionality
                    {
                        Session["ZipCode"] = txtZipCode.Text.Trim();
                        Session["City"] = txtCity.Text.Trim();
                        Session["Travel_Dis"] = ddlDistance.SelectedItem.Value.Trim();
                        //   Session["State"] = 1;// ddlState.SelectedItem.Value.Trim();

                        Session["State"] = ddlState.SelectedItem.Value.Trim();
                    }
                    qstring = qstring.ToString().Trim().Replace("(", "_");
                    qstring = qstring.ToString().Trim().Replace(")", "_");
                    qstring = qstring.ToString().Trim().Replace("_&_", "_");
                    qstring = qstring.ToString().Trim().Replace("[", "_");
                    qstring = qstring.ToString().Trim().Replace("]", "_");
                    qstring = qstring.ToString().Trim().Replace("\\", "_");
                    qstring = qstring.ToString().Trim().Replace("//", "_");
                    qstring = qstring.ToString().Trim().Replace("-", "_");
                    qstring = qstring.ToString().Trim().Replace("___", "_");
                    qstring = qstring.ToString().Trim().Replace("__", "_");
                    if (qstring != "")
                    {
                        Response.Redirect(qstring.ToString().Trim() + "/doctors.aspx", true);
                        //Response.Redirect(Session["strHttp"] + "DoctorSearchPage.aspx", false);
                    }
                    else
                    {
                        Response.Redirect("search" + "/doctors.aspx", true);
                    }

                }
                else
                {
                   lblMesg.Text = "No records found. Please try again.";
                    lblMesg.ForeColor = System.Drawing.Color.Red;
                    lblMesg.Font.Bold = true;
                    Session["NoDocResult"] = "true";
                }
            }
            catch (Exception ex)
            {
                lblMesg.Visible = true;
                lblMesg.Text = ex.ToString();
                // lblMesg.Text ="An error occured while processing request.";
                lblMesg.ForeColor = System.Drawing.Color.Red;
            }

            #endregion
            #endregion
        }
        else if (ddlDind.SelectedValue == "Dentist")
        {
            #region "Dentist Search"

            Session["Speciality"] = "";
            string qstring = "";

            if (ddlDentistSpeciality.Items.Count > 1)
            {
                if (ddlDentistSpeciality.SelectedIndex > 0)
                {
                    Session["Speciality"] = ddlDentistSpeciality.SelectedItem.Text.Trim().Replace(" ", "_");
                    qstring = Session["Speciality"].ToString();
                    //end
                }
            }

            if (ddlState.Items.Count > 1)
            {
                if (ddlState.SelectedIndex > 0)
                {
                 

                    if (qstring == "")
                        qstring = ddlState.SelectedItem.Text.Trim().Replace(" ", "_");
                    else
                        qstring = qstring + "/" + ddlState.SelectedItem.Text.Trim().Replace(" ", "_");

                    //End
                }
            }


            if (txtCity.Text.Trim().Equals("City :") || txtCity.Text.Trim() == "")
                txtCity.Text = "";
            else if (qstring == "")
            {
                //qstring = "?city=" + txtCity.Text.Trim().Replace(" ", "_");
                qstring = txtCity.Text.Trim().Replace(" ", "_");
            }
            else
            {
                //qstring = qstring + "&city=" + txtCity.Text.Trim().Replace(" ", "_");
                qstring = qstring + "/" + txtCity.Text.Trim().Replace(" ", "_");
            }

            if (txtZipCode.Text.Trim().Equals("Zipcode:") || txtZipCode.Text.Trim() == "")
                txtZipCode.Text = "";
            else if (qstring == "")
            {
                //qstring = "?zip=" + txtZipCode.Text.Trim().Replace(" ", "_");
                qstring = txtZipCode.Text.Trim().Replace(" ", "_");

            }
            else
            {
                //qstring = qstring + "&zip=" + txtZipCode.Text.Replace(" ", "_");
                qstring = qstring + "/" + txtZipCode.Text.Replace(" ", "_");

            }

            if (txtLName.Text.Trim().Equals("Last Name:"))
                txtLName.Text = "";

            Session["sDentistsId"] = "";
            Session["PreDoctorsId"] = "";
            Session["EnFeaDoctorsId"] = "";
            Session["StdFeaDoctorsId"] = "";
            Session["Travel_Dis"] = "";
            Session["Top3"] = "";
            Session["ZipCode"] = "";
            Session["City"] = "";
            Session["State"] = "";
            Session["sDentistId"] = ""; // DoctorsNonFeaIds;
            Session["PreDentistId"] = ""; // PremiumDoctorsFeaturedIds;
            Session["EnDentistId"] = ""; // EnhancedDoctorsFeaturedIds;
            Session["StdDentistId"] = ""; // StandardDoctorsFeaturedIds;
            #region calling stored procedure
            // get the search results
            string[] strSpID = ddlDentistSpeciality.SelectedValue.Split(',');
             try
            {               
                SqlParameter[] sqlParam = new SqlParameter[9];
                sqlParam[0] = new SqlParameter("@state", SqlDbType.VarChar, 2);
                sqlParam[1] = new SqlParameter("@city", SqlDbType.VarChar, 50);
                sqlParam[2] = new SqlParameter("@zip", SqlDbType.VarChar, 10);
                sqlParam[3] = new SqlParameter("@SpecialtyID", SqlDbType.Int);
                sqlParam[4] = new SqlParameter("@Rate", SqlDbType.Int);
                sqlParam[5] = new SqlParameter("@FirstName", SqlDbType.VarChar, 200);
                sqlParam[6] = new SqlParameter("@LastName", SqlDbType.VarChar, 200);
                sqlParam[7] = new SqlParameter("@SubSpecialtyID", SqlDbType.Int);
                sqlParam[8] = new SqlParameter("@TravelDistance", SqlDbType.Float);

                sqlParam[0].Value = ddlState.SelectedItem.Value.Equals("0") ? "" : ddlState.SelectedItem.Value;
                sqlParam[1].Value = txtCity.Text.Trim();
                sqlParam[2].Value = txtZipCode.Text.Trim();
                sqlParam[3].Value = strSpID[0]; // ddlSpeciality.SelectedItem.Value;
                sqlParam[4].Value = ddlRating.SelectedItem.Value;
                sqlParam[5].Value = "";
                sqlParam[6].Value = txtLName.Text.Trim();
                sqlParam[7].Value = ddlDentistSubSpeciality.SelectedItem.Value;
                sqlParam[8].Value = ddlDistance.SelectedItem.Value;

                //DataSet ds_result = mgr.ExecuteQuery("DentistSearch_HomePage", sqlParam, "tbl_srch");
                DataSet ds_result = mgr.ExecuteQuery("HomepageDentSearch", sqlParam, "tbl_srch");

                string DoctorsNonFeaIds = GetDentistId(ds_result);
                string PremiumDoctorsFeaturedIds = GetPremiumDentistsIdFeat(ds_result, 1);
                string EnhancedDoctorsFeaturedIds = GetEnhancedDentistsIdFeat(ds_result, 1);
                string StandardDoctorsFeaturedIds = GetStandardDentistsIdFeat(ds_result, 1);
                // get top 3
                string Top3DrFeaturedIds = GetPremiumDentistsIdFeat(ds_result, 1);

                if ((DoctorsNonFeaIds.Trim().Length > 0) || (PremiumDoctorsFeaturedIds.Trim().Length > 0) || (Top3DrFeaturedIds.Trim().Length > 0) || (EnhancedDoctorsFeaturedIds.Trim().Length > 0) || (StandardDoctorsFeaturedIds.Trim().Length > 0))
                {
                    Session["Top3"] = Top3DrFeaturedIds;
                    Session["pageFromOrAction"] = "home";
                    Session["PreviousSpeciality"] = "";
                    Session["PreviousSubSpeciality"] = "";
                       if (ddlSpeciality.SelectedIndex > 0)
                        Session["PreviousSpeciality"] = ddlDentistSpeciality.SelectedItem.Text;
                    if (ddlSubSpeciality.SelectedIndex > 0)
                        Session["PreviousSubSpeciality"] = ddlDentistSubSpeciality.SelectedItem.Text;
                  
                    Session["sDentistId"] = DoctorsNonFeaIds; // DoctorsNonFeaIds;
                    Session["PreDentistId"] = PremiumDoctorsFeaturedIds; // PremiumDoctorsFeaturedIds;
                    Session["EnDentistId"] = EnhancedDoctorsFeaturedIds; // EnhancedDoctorsFeaturedIds;
                    Session["StdDentistId"] = StandardDoctorsFeaturedIds; // StandardDoctorsFeaturedIds;

                    if (ddlDistance.SelectedItem.Value.Trim() != "0") // to implement Distance Search Functionality
                    {
                         Session["ZipCode"] = txtZipCode.Text.Trim();
                        Session["City"] = txtCity.Text.Trim();
                        Session["Travel_Dis"] = ddlDistance.SelectedItem.Value.Trim();
                        Session["State"] = ddlState.SelectedItem.Value.Trim();
                  
                    }
                  
                    qstring = qstring.ToString().Trim().Replace("(", "_");
                    qstring = qstring.ToString().Trim().Replace(")", "_");
                    qstring = qstring.ToString().Trim().Replace("_&_", "_");
                    qstring = qstring.ToString().Trim().Replace("[", "_");
                    qstring = qstring.ToString().Trim().Replace("]", "_");
                    qstring = qstring.ToString().Trim().Replace("\\", "_");
                    qstring = qstring.ToString().Trim().Replace("//", "_");
                    qstring = qstring.ToString().Trim().Replace("-", "_");
                    qstring = qstring.ToString().Trim().Replace("___", "_");
                    qstring = qstring.ToString().Trim().Replace("__", "_");

                    if (qstring != "")
                    {
                        Response.Redirect(qstring.ToString().Trim() + "/dentist.aspx", true);
                    }
                    else
                    {
                        Response.Redirect("search" + "/dentists.aspx", true);
                    }
                }
                else
                {
                    lblMesg.Text = "No records found based on the criteria specified. Please try again.";
                    lblMesg.ForeColor = System.Drawing.Color.Red;
                    lblMesg.Font.Bold = true;
                    Session["NoDenResult"] = "true";
                    if (ddlDind.SelectedValue == "Dentist")
                    {
                        ddlSpeciality.Visible = false;
                        //DentisDDL();
                    }
                }
            }
            catch (Exception ex)
            {
                lblMesg.Visible = true;
                lblMesg.Text = "An error occured while processing request.";
                lblMesg.ForeColor = System.Drawing.Color.Red;
            }

            #endregion

            #endregion
        }
    }

    /// <summary>
    /// Get the doctorsids of non-featured doctors into a string
    /// </summary>
    /// <param name="ds"></param>
    /// <returns></returns>

    

   
    /// <summary>
    /// get featured dr id s j=2 means get top 3
    /// </summary>
    /// <param name="ds"></param>
    /// <param name="j"></param>
    /// <returns></returns>
    
    #region "Dentist Search Helper Functions"
    private string GetDoctorsId(DataSet ds)
    {
        string DoctorsIds = "";

        try
        {
            // DataSet ds = mgr.ExecuteQuery(sql, "tblResults");
            if (ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (i == 0)
                    {
                        DoctorsIds = ds.Tables[0].Rows[i][0].ToString();
                    }
                    else
                    {
                        DoctorsIds += "," + ds.Tables[0].Rows[i][0].ToString();
                    }
                }
            }
        }
        catch
        {
            DoctorsIds = "";
        }

        return DoctorsIds;


    }
    private string GetPremiumDoctorsIdFeat(DataSet ds, int j)
    {
        string DoctorsIds = "";

        try
        {

            // DataSet ds = mgr.ExecuteQuery(sql, "tblResults");
            if (ds.Tables[3].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[3].Rows.Count; i++)
                {
                    if (i == 0)
                    {
                        DoctorsIds = ds.Tables[3].Rows[i][0].ToString();
                    }
                    else
                    {
                        DoctorsIds += "," + ds.Tables[3].Rows[i][0].ToString();
                    }
                }
            }
        }


        catch
        {
            DoctorsIds = "";
        }

        return DoctorsIds;






    }
    private string GetEnhancedDoctorsIdFeat(DataSet ds, int j)
    {
        string DoctorsIds = "";

        try
        {

            // DataSet ds = mgr.ExecuteQuery(sql, "tblResults");
            if (ds.Tables[2].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[2].Rows.Count; i++)
                {
                    if (i == 0)
                    {
                        DoctorsIds = ds.Tables[2].Rows[i][0].ToString();
                    }
                    else
                    {
                        DoctorsIds += "," + ds.Tables[2].Rows[i][0].ToString();
                    }
                }
            }
        }


        catch
        {
            DoctorsIds = "";
        }

        return DoctorsIds;


    }
    private string GetStandardDoctorsIdFeat(DataSet ds, int j)
    {
        string DoctorsIds = "";

        try
        {

            // DataSet ds = mgr.ExecuteQuery(sql, "tblResults");
            if (ds.Tables[1].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[1].Rows.Count; i++)
                {
                    if (i == 0)
                    {
                        DoctorsIds = ds.Tables[1].Rows[i][0].ToString();
                    }
                    else
                    {
                        DoctorsIds += "," + ds.Tables[1].Rows[i][0].ToString();
                    }
                }
            }
        }


        catch
        {
            DoctorsIds = "";
        }

        return DoctorsIds;


    }

    protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
    {
        string countryID = ddlCountry.SelectedValue;
        // mgr.BindList("select countrycode,countryname from tbl_country", "countryname", "countrycode", ddlCountry, "select");
        mgr.BindList("select stateid,name from tbl_states where CountryID='" + countryID + "'  order by name", "Name", "StateId", ddlState,"");
        if (ddlCountry.SelectedValue == "US")
        {
            ddlState.Items.Insert(0, new ListItem("Select a State", "0"));
        }
        else
        {
            ddlState.Items.Insert(0, new ListItem("Select a Province", "0"));  
        }
    }

    #endregion

    #region "Dentist Search Helper Functions"
    private string GetDentistId(DataSet ds)
    {
        string DentistIds = "";
        try
        {
            if (ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    if (i == 0)
                    { DentistIds = ds.Tables[0].Rows[i][0].ToString(); }
                    else
                    { DentistIds += "," + ds.Tables[0].Rows[i][0].ToString(); }
                }
            }
        }
        catch
        {
            DentistIds = "";
        }
        return DentistIds;
    }
    private string GetPremiumDentistsIdFeat(DataSet ds, int j)
    {
        string DentistsIds = "";
        int count = 0;
        int k = 0;
        try
        {
            if (ds.Tables[1].Rows.Count > 0)
            {
                if (j == 2)
                {
                    if (ds.Tables[1].Rows.Count > 3)
                    {
                        count = 3;
                    }
                    else
                    {
                        count = ds.Tables[1].Rows.Count;
                    }

                    k = 0;
                }
                else
                {
                    count = ds.Tables[1].Rows.Count;
                    //    k = 3;
                }
                //ds.Tables[1].Rows.Count
                for (int i = k; i < count; i++)
                {
                    if ((i == 0) || (i == 3))
                    {
                        DentistsIds = ds.Tables[1].Rows[i][0].ToString();
                    }
                    else
                    {
                        DentistsIds += "," + ds.Tables[1].Rows[i][0].ToString();
                    }
                }
            }
        }
        catch
        {
            DentistsIds = "";
        }

        return DentistsIds;


    }
    private string GetEnhancedDentistsIdFeat(DataSet ds, int j)
    {
        string DoctorsIds = "";

        try
        {

            // DataSet ds = mgr.ExecuteQuery(sql, "tblResults");
            if (ds.Tables[2].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[2].Rows.Count; i++)
                {
                    if (i == 0)
                    {
                        DoctorsIds = ds.Tables[2].Rows[i][0].ToString();
                    }
                    else
                    {
                        DoctorsIds += "," + ds.Tables[2].Rows[i][0].ToString();
                    }
                }
            }
        }


        catch
        {
            DoctorsIds = "";
        }

        return DoctorsIds;


    }
    private string GetStandardDentistsIdFeat(DataSet ds, int j)
    {
        string DoctorsIds = "";

        try
        {

            // DataSet ds = mgr.ExecuteQuery(sql, "tblResults");
            if (ds.Tables[3].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[3].Rows.Count; i++)
                {
                    if (i == 0)
                    {
                        DoctorsIds = ds.Tables[3].Rows[i][0].ToString();
                    }
                    else
                    {
                        DoctorsIds += "," + ds.Tables[3].Rows[i][0].ToString();
                    }
                }
            }
        }


        catch
        {
            DoctorsIds = "";
        }

        return DoctorsIds;


    }
    #endregion
}
